Repository navigation
feat(mcpx): spawn-time ${mcpx.root}/${mcpx.cwd} substitution + load validation (#960) - #5135
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad5edcef9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| eff, err := p.cfg.Effective(rs.Root, rs.Cwd) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
Preserve the creating caller's cwd across instance replacement
For any server using ${mcpx.cwd}, the initial caller-driven spawn succeeds, but a non-lazy restart stops the working child and fails to start its replacement. Instance retains only rs.Root, while Restart reconstructs ResolvedScope{Key, Root} and execwatch.replaceChild and the subscription monitor similarly omit Cwd. Consequently, this new Effective call rejects those replacements because the caller cwd is empty. Store the creating caller's cwd with the instance and propagate it through replacement paths, just as the root is preserved.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 701a4d6: Instance now stores the creating callers cwd alongside root(set at startLane creation), and every pool-driven replacement path propagates it —Restart(roots+cwds maps),execwatch.replaceChild, the subscription monitor (watchCwdcaptured withwatchRoot), and handoff adoption (InstanceHandoff.Cwd). Regression tests: TestRestartPreservesCallerCwdandTestExecWatchReplacesPlaceholderCwdChild` in pkgs/mcpx/internal/pool/codex5135_test.go (pool/config/daemon suites pass on the laptop).
| spawnCwd, cwdSource = "", "daemon" | ||
| } | ||
| execStamp, execIdentity, _ := p.cfg.ExecStateAt(spawnCwd) | ||
| execStamp, execIdentity, _ := eff.ExecStateAt(spawnCwd) |
There was a problem hiding this comment.
Use the effective definition for executable monitoring too
With a relative command such as ./server and cwd: "${mcpx.root}", startup now correctly resolves and runs the executable under the substituted directory, but executable monitoring still inspects the raw definition. In execwatch.go, checkExec takes the pool-wide branch because ExecUsesScopeRoot() requires an empty configured cwd, then p.cfg.ExecStamp() searches under the literal ${mcpx.root} directory. It therefore reports the executable missing and never detects updates to the running server. Preserve the effective definition or equivalent per-instance resolution inputs and use them for subsequent executable checks as well as this initial stamp.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 701a4d6: checkInstanceExec now stamps the instances effective (substituted) definition (p.cfg.Effective(in.root, in.cwd)+ExecStampAton the effective spawn cwd) instead of the raw stored definition, andExecUsesScopeRootalso returns true for a config cwd referencing ${mcpx.root}/${mcpx.cwd} so those pools route to the per-instance check rather than the pool-wide literal-placeholder stamp. Regression test:TestExecWatchReplacesPlaceholderCwdChild(a./server` under cwd "${mcpx.root}" is replaced when its executable changes).
| eff, err := p.cfg.Effective(rs.Root, rs.Cwd) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
Carry caller scope into schema discovery for placeholder servers
For a worktree-scoped server using ${mcpx.root} with no cached schemas, discovery always fails: refreshSchemas calls Acquire with only the synthetic schema key (pool.go:1137), so this substitution receives an empty root even when a foreground request has a valid caller workspace. Registry.Warm uses that path, leaving search and generated tool signatures empty; an ordinary caller-backed tool call does not populate the schema cache either. Foreground confirmation and annotation-dependent write-policy checks also invoke this rootless refresh despite having the caller context (consumer.go:448,638), preventing otherwise valid calls. Thread the caller's resolved scope into foreground schema discovery and defer caller-dependent background warming rather than manufacturing a root.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 701a4d6: schema refresh is now caller-scoped in the foreground — new Pool.RefreshSchemasFor(ctx, rs) acquires under the callers resolved scope, and the daemon consumers three foreground refresh sites (confirmDestructive, write-policy classification, ledger read-only check) pass r.resolvedFor(p, cc). The unscoped RefreshSchemas defers caller-scoped definitions (Pool.CallerScoped) with an explicit error instead of manufacturing a rootless start, and Registry.Warm skips caller-scoped pools so background warming no longer records a guaranteed failure. Regression test: TestRefreshSchemasForCallerScope.
…ma refresh (#960) Codex review on PR #5135, three P2 findings: (1) Instance now stores the creating caller cwd alongside root and propagates it through Restart, exec-watch replacement, the subscription monitor, and handoff adoption; (2) exec monitoring resolves the effective (substituted) definition per instance and placeholder config cwds route to the per-instance check; (3) schema refresh gains RefreshSchemasFor on the caller resolved scope (consumer foreground paths threaded), unscoped refresh defers caller-scoped definitions instead of starting rootless, and registry Warm skips caller-scoped pools. Regression tests in codex5135_test.go.
Implements #960 (decision 0004 §4, slice 2) · queue task 4874 · prerequisite #958 (slice 1) is closed and
ResolvedScopeis on main, so the gate named in the issue is lifted.What
internal/config/placeholders.go, called fromConfig.Resolve): any${mcpx.<name>}token with an unknown name, and any malformed${mcpx.sequence (unterminated, empty, bad characters), in a server'sargs,envvalues orcwdis a config error naming the server and the field. Every other${...}form passes through verbatim, as today.Resolved.Effective(root, callerCwd)builds the per-instance spawn definition —${mcpx.root}→ the instance's resolved root,${mcpx.cwd}→ the creating caller's cwd — overArgs, everyEnvvalue, andCwd. The stored/merged config is never mutated; config output keeps showing placeholders.ResolvedScopenow carries the canonicalized callerCwdalongsideRoot(fixed at instance creation, never re-resolved, per §2).${mcpx.root}with an empty resolved root (or${mcpx.cwd}with no caller cwd) fails the spawn instartLanebefore anything starts, naming server and field.startLanenow hashes the effective (substituted) definition withpool.Identity, so two instances differing only by substituted root never share an era entry.dialtakes the effective definition; HTTP session adoption passes the stored config (nothing spawns there).Tests
internal/config/placeholders_test.go: validation matrix (unknown/malformed in each field, non-mcpx pass-through), substitution in Args/Env/Cwd including multi-placeholder values, stored config untouched, empty root/cwd failures.internal/pool/placeholders_test.go: end-to-end spawn against the fake MCP server — the child process observes the substituted env values for both placeholders; Acquire with no root fails loudly naming server + placeholder; era identities differ across substituted roots and are stable for the same one.internal/config,internal/pool,internal/daemonsuites pass;go vetclean; darwin/arm64 build + test-compile clean for the touched packages.internal/conformanceandinternal/defaultslink tests fail identically on a pristine worktree of current main (environmental — they need a bound mcpx binary / generated docs tree).Cross-repo note
mcpx also lives in dezren39/nix. Per the one-change-one-issue rule this PR is the code side of the set; the nix port is owed and recorded as a SET-REMAINDER in the code backlog (
hidden_files/backlog-code.md) so the next nix pass ports from issue #960 instead of rediscovering it.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.